package com.java.zhuiyun.api.member_manager.controller;

import com.java.zhuiyun.api.member_manager.entity.MemberType;
import com.java.zhuiyun.api.member_manager.service.MemberTypeService;
import com.java.zhuiyun.common.response.CommonResult;
import com.java.zhuiyun.util.pageUtil.PageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @ClassName MemberTypeController
 * @Description TODO 会员类型管理
 * @Author WX
 * @Date 2023/8/14 19:03
 **/
@RestController
@CrossOrigin
@Api(tags = "会员类型管理")
@RequestMapping("/memberType")
public class MemberTypeController {
    @Autowired
    private MemberTypeService memberTypeService;

    /*
    * @Author WX
    * @Description TODO 查询所有类型数据
    * @Date 2023/8/14 19:22
    * @Return
    * @param MemberType,PageRequest
    */
    @PostMapping("/selectMemberType")
    @ApiOperation(value = "会员类型查询方法")
    public CommonResult selectMemberType(@RequestBody MemberType memberType, PageRequest pageRequest){
        String memberName = memberType.getMemberName();
        if (memberName != null && !memberName.trim().isEmpty()) {
            return memberTypeService.selectMoHuMemberType(memberType,pageRequest);
        }else {
            memberType.setMemberName(null);
            return memberTypeService.selectMemberType(memberType,pageRequest);
        }
    }

    /*
     * @Author WX
     * @Description TODO 查询一条类型数据
     * @Date 2023/8/14 19:22
     * @Return
     * @param id
     */
   @RequestMapping("/fingById")
   @ApiOperation(value = "会员类型只查询一条方法")
    public CommonResult fingById(Integer id){
       System.out.println(id);
       return CommonResult.ok(memberTypeService.fingById(id));
   }

    /*
     * @Author WX
     * @Description TODO 修改状态
     * @Date 2023/8/14 19:22
     * @Return
     * @param memberType
     */
   @PostMapping("/updateModify")
   @ApiOperation(value = "修改状态")
    public CommonResult updateModify(@RequestBody MemberType memberType){
       return CommonResult.ok(memberTypeService.updateModify(memberType));
   }

    /*
     * @Author WX
     * @Description TODO 修改类型
     * @Date 2023/8/14 19:22
     * @Return
     * @param memberType
     */
    @PostMapping("/updateMemberType")
    @ApiOperation(value = "修改类型")
    public CommonResult updateMemberType(MemberType memberType, MultipartFile file){
        return CommonResult.ok(memberTypeService.updateMemberType(memberType,file));
    }

    /*
     * @Author WX
     * @Description TODO 添加类型
     * @Date 2023/8/14 19:22
     * @Return
     * @param memberType
     */
    @PostMapping("/addMemberType")
    @ApiOperation(value = "添加类型")
    public CommonResult addMemberType(MultipartFile file,MemberType memberType){
        System.out.println(file);
        System.out.println(memberType);
        return CommonResult.ok(memberTypeService.addMemberType(memberType,file));
    }

    /*
     * @Author WX
     * @Description TODO 删除类型
     * @Date 2023/8/14 19:22
     * @Return
     * @param id
     */
    @RequestMapping("/deleteById")
    @ApiOperation(value = "删除类型")
    public CommonResult deleteById(Integer id){
        return CommonResult.ok(memberTypeService.deleteById(id));
    }

    /*
    * @Author WX
    * @Description 查询会员类型
    * @Date 2023/8/30 10:09
    * @Return
    * @param null
    */
    @RequestMapping("/getMemberList")
    public CommonResult getMemberList(){
        return CommonResult.ok(memberTypeService.getMemberList());
    }

    /*
    * @Author WX
    * @Description pc端会员类型查询
    * @Date 2023/9/2 11:21
    * @Return
    * @param null
    */
    @RequestMapping("/selectMemberList")
    public CommonResult selectMemberList () {
        return CommonResult.ok(memberTypeService.selectMemberList());
    }
}
